package com.xh.hongaicodegenerator.langgraph4j.node;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ImageCollectionThreadPoolConfig {
    
    @Bean("imageCollectionTaskExecutor")
    public ExecutorService imageCollectionTaskExecutor() {
        return new ThreadPoolExecutor(
            4,  // 核心线程数
            8, // 最大线程数
            60L, TimeUnit.SECONDS,  // 空闲线程存活时间
            new LinkedBlockingQueue<>(1000),  // 任务队列
            new ThreadFactoryBuilder().setNameFormat("image-collection-%d").build(),
            new ThreadPoolExecutor.CallerRunsPolicy()  // 拒绝策略
        );
    }
}
